package com.glela.goods.service.impl;

import com.glela.cache.model.RedisKey;
import com.glela.cache.redis.RedisUtil;
import com.glela.goods.mapper.AnswerQuestionMapper;
import com.glela.goods.service.AnswerQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AnswerQuestionServiceImpl implements AnswerQuestionService {

    @Autowired
    private AnswerQuestionMapper answerQuestionMapper;

    @Autowired
    private RedisUtil redisUtil;

    @Override
    public int getCountByUid(int uid) {
        if (redisUtil.sismember(RedisKey.REDIS_KEY_ANSWERED_QUESTION,uid+"")){
            return 1;
        }
        int count = answerQuestionMapper.getCountByUid(uid);
        if (count>0){
            redisUtil.sadd(RedisKey.REDIS_KEY_ANSWERED_QUESTION,uid+"");
        }
        return count;
    }

    @Override
    public int addAnswerQuestion(int uid) {
        int count = 0;
        try {
            count = answerQuestionMapper.addAnswerQuestion(uid);
        }catch (Exception e){

        }
        if (count>0){
            redisUtil.sadd(RedisKey.REDIS_KEY_ANSWERED_QUESTION,uid+"");
        }
        return count;
    }
}
